package com.estar.assistsurvy.thread;

import java.io.File;
import com.estar.assistsurvy.constant.Constants;
import com.estar.assistsurvy.entity.RequestAreaInfo;
import com.estar.assistsurvy.entity.ResponseAreaInfo;
import com.estar.assistsurvy.utils.FileUtils;

import android.content.Context;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;

public class AreaInfoThread extends BaseThread {

	private RequestAreaInfo requestArea;
	private static final String FILE_HOME=Environment.getExternalStorageDirectory()+File.separator+"areaAndBanks/";


	public AreaInfoThread(Context context, Handler handler, RequestAreaInfo requestArea) {
		super(context, handler);
		this.requestArea = requestArea;
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		url_str=Constants.NAMESPACE+Constants.AREAINFO;
		json=gson.toJson(requestArea);
		postRequest(url_str, json);
		Log.i("wl", "省市获取返回值"+result);
		if(result!=null){
//				result=result.replaceAll("(\r\n|\r|\n|\n\r)", "");
			FileUtils.writeTxtToFile(result, FILE_HOME, "areaList.txt");
			ResponseAreaInfo areaInfo=new ResponseAreaInfo();
			areaInfo=gson.fromJson(result, ResponseAreaInfo.class);
			msg.what=2;
			msg.obj=areaInfo;
			msg.sendToTarget();
		}
	}
}
